 package server.maps;

 import client.MapleCharacter;
import client.MapleClient;
import scripting.reactor.ReactorScriptManager;
import server.Timer;
import tools.MaplePacketCreator;
import tools.Pair;

import java.awt.*;









 public class MapleReactor
   extends MapleMapObject {
   private int rid;
   private MapleReactorStats stats;
/*  16 */   private byte state = 0; private byte facingDirection = 0; private byte properEventIdx = 0; private byte stateEnd = 0;
/*  17 */   private int delay = -1;
   private MapleMap map;
/*  19 */   private String name = ""; private boolean timerActive = false;
   private boolean alive = true;
/*  21 */   private Point srcPos = new Point(); private boolean custom = false; private boolean pqAction = false;
/*  22 */   private short stance = 0;
   private int ownerID;

   public MapleReactor(MapleReactorStats stats, int rid) {
/*  26 */     this.stats = stats;
/*  27 */     this.rid = rid;
   }

   public Point getSrcPos() {
/*  31 */     return this.srcPos;
   }

   public void setSrcPos(Point srcPos) {
/*  35 */     this.srcPos = srcPos;
   }

   public int getRid() {
/*  39 */     return this.rid;
   }

   public void setRid(int rid) {
/*  43 */     this.rid = rid;
   }

   public MapleReactorStats getStats() {
/*  47 */     return this.stats;
   }

   public void setStats(MapleReactorStats stats) {
/*  51 */     this.stats = stats;
   }

   public boolean isCustom() {
/*  55 */     return this.custom;
   }

   public void setCustom(boolean c) {
/*  59 */     this.custom = c;
   }

   public byte getFacingDirection() {
/*  63 */     return this.facingDirection;
   }

   public void setFacingDirection(byte facingDirection) {
/*  67 */     this.facingDirection = facingDirection;
   }

   public boolean isTimerActive() {
/*  71 */     return this.timerActive;
   }

   public void setTimerActive(boolean active) {
/*  75 */     this.timerActive = active;
   }

   public int getReactorId() {
/*  79 */     return this.rid;
   }

   public byte getState() {
/*  83 */     return this.state;
   }

   public void setState(byte state) {
/*  87 */     this.state = state;
   }

   public boolean isAlive() {
/*  91 */     return this.alive;
   }

   public void setAlive(boolean alive) {
/*  95 */     this.alive = alive;
   }

   public int getDelay() {
/*  99 */     return this.delay;
   }

   public void setDelay(int delay) {
/* 103 */     this.delay = delay;
   }


   public MapleMapObjectType getType() {
/* 108 */     return MapleMapObjectType.REACTOR;
   }

   public int getReactorType() {
/* 112 */     return this.stats.getType(this.state);
   }

   public byte getTouch() {
/* 116 */     return this.stats.canTouch(this.state);
   }

   public MapleMap getMap() {
/* 120 */     return this.map;
   }

   public void setMap(MapleMap map) {
/* 124 */     this.map = map;
   }

   public Pair<Integer, Integer> getReactItem() {
/* 128 */     return this.stats.getReactItem(this.state);
   }

   public boolean isPqAction() {
/* 132 */     return this.pqAction;
   }

   public void setPqAction(boolean pqAction) {
/* 136 */     this.pqAction = pqAction;
   }


   public void sendDestroyData(MapleClient client) {
/* 141 */     client.announce(MaplePacketCreator.destroyReactor(this));
   }


   public void sendSpawnData(MapleClient client) {
/* 146 */     client.announce(MaplePacketCreator.spawnReactor(this));
   }

   public void forceStartReactor(MapleClient c) {
/* 150 */     ReactorScriptManager.getInstance().act(c, this);
   }

   public void forceHitReactor(byte newState) {
/* 154 */     forceHitReactor(newState, 0, 0, 0);
   }

   public void forceHitReactor(byte newState, int stateEnd, int cid, int properEventIdx) {
/* 158 */     setState(newState);
/* 159 */     setTimerActive(false);
/* 160 */     setStateEnd((byte)stateEnd);
/* 161 */     setOwnerID(cid);
/* 162 */     setProperEventIdx((byte)properEventIdx);
/* 163 */     this.map.broadcastMessage(MaplePacketCreator.triggerReactor(this));
   }


   public void hitReactor(MapleClient c) {
/* 168 */     hitReactor(0, (short)0, c);
   }

   public void forceTrigger() {
/* 172 */     this.map.broadcastMessage(MaplePacketCreator.triggerReactor(this));
   }

   public void delayedDestroyReactor(long delay) {
/* 176 */     Timer.MapTimer.getInstance().schedule(() -> this.map.destroyReactor(getObjectId()), delay);
   }

   public void hitReactor(int charPos, short stance, MapleClient c) {
/* 180 */     setStance(stance);
/* 181 */     if (this.stats.getType(this.state) < 999 && this.stats.getType(this.state) != -1) {

/* 183 */       byte oldState = this.state;
/* 184 */       if (this.stats.getType(this.state) != 2 || (charPos != 0 && charPos != 2)) {
/* 185 */         this.state = this.stats.getNextState(this.state);

/* 187 */         if (this.stats.getNextState(this.state) == -1 || this.stats.getType(this.state) == 999) {
/* 188 */           if ((this.stats.getType(this.state) < 100 || this.stats.getType(this.state) == 999) && this.delay > 0) {
/* 189 */             this.map.destroyReactor(getObjectId());
           } else {
/* 191 */             this.map.broadcastMessage(MaplePacketCreator.triggerReactor(this));
           }

/* 194 */           ReactorScriptManager.getInstance().act(c, this);
         } else {

/* 197 */           if ((this.rid == 9239001 || this.rid == 2008009) && !isPqAction()) {
/* 198 */             setSrcPos(getTruePosition());
/* 199 */             setPqAction(true);
/* 200 */             setState((byte)1);
/* 201 */             setStateEnd((byte)2);
           }
/* 203 */           else if (isPqAction()) {
/* 204 */             setPqAction(false);
/* 205 */             c.getPlayer().setReactor(null);
/* 206 */             setOwnerID(0);
/* 207 */             ReactorScriptManager.getInstance().act(c, this);
           }

/* 210 */           this.map.broadcastMessage(MaplePacketCreator.triggerReactor(this));
/* 211 */           boolean done = false;
/* 212 */           if (this.state == this.stats.getNextState(this.state) || this.rid == 2618000 || this.rid == 2309000) {
/* 213 */             if (this.rid > 200011) {
/* 214 */               ReactorScriptManager.getInstance().act(c, this);
             }
/* 216 */             done = true;
           }
/* 218 */           if (this.stats.getTimeOut(this.state) > 0) {
/* 219 */             if (!done && this.rid > 200011) {
/* 220 */               ReactorScriptManager.getInstance().act(c, this);
             }
/* 222 */             scheduleSetState(c.getPlayer(), this.state, oldState, this.stats.getTimeOut(this.state));
           }
         }
       }
     }
   }

   public int getOwnerID() {
/* 230 */     return this.ownerID;
   }

   public void setOwnerID(int ownerID) {
/* 234 */     this.ownerID = ownerID;
   }

   public byte getProperEventIdx() {
/* 238 */     return this.properEventIdx;
   }

   public void setProperEventIdx(byte properEventIdx) {
/* 242 */     this.properEventIdx = properEventIdx;
   }

   public byte getStateEnd() {
/* 246 */     return this.stateEnd;
   }

   public void setStateEnd(byte stateEnd) {
/* 250 */     this.stateEnd = stateEnd;
   }

   public short getStance() {
/* 254 */     return this.stance;
   }

   public void setStance(short stance) {
/* 258 */     this.stance = stance;
   }

   public Rectangle getArea() {
/* 262 */     int height = (this.stats.getBR()).y - (this.stats.getTL()).y;
/* 263 */     int width = (this.stats.getBR()).x - (this.stats.getTL()).x;
/* 264 */     int origX = (getTruePosition()).x + (this.stats.getTL()).x;
/* 265 */     int origY = (getTruePosition()).y + (this.stats.getTL()).y;
/* 266 */     return new Rectangle(origX, origY, width, height);
   }

   public String getName() {
/* 270 */     return this.name;
   }

   public void setName(String name) {
/* 274 */     this.name = name;
   }


   public String toString() {
/* 279 */     return "反应堆 工作ID:" + getObjectId() + " ReactorID: " + this.rid + " 坐标: " + (getPosition()).x + "/" + (getPosition()).y + " 状态: " + this.state + " 类型: " + this.stats.getType(this.state);
   }

   public void delayedHitReactor(MapleClient c, long delay) {
/* 283 */     Timer.MapTimer.getInstance().schedule(() -> hitReactor(c), delay);
   }

   public void scheduleSetState(MapleCharacter chr, byte oldState, byte newState, long delay) {
/* 287 */     Timer.MapTimer.getInstance().schedule(() -> { if (this.state == oldState) forceHitReactor(newState);  },delay);
   }
 }


/* Location:              C:\PGX\Server.jar!\server\maps\MapleReactor.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */